package com.zyd.androidwifi;

import androidx.appcompat.app.AppCompatActivity;

import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.zyd.androidwifi.broadcas.NetworkConnectChangedReceiver;

public class WifiMonitorActivity extends AppCompatActivity {
    private NetworkConnectChangedReceiver changedReceiver;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wifi_monitor);
        changedReceiver = new NetworkConnectChangedReceiver(this);


    }

    @Override
    protected void onStart() {
        super.onStart();
        //注册监听WIFI广播
        IntentFilter filter = new IntentFilter();
        filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
        filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
        //当网络状态发生变化时，系统发出的正是一条值为android.net.conn.CONNECTIVITY_CHANGE的广播
        filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
        registerReceiver(changedReceiver, filter);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //销毁广播
        unregisterReceiver(changedReceiver);
    }
}